import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ArrayListDemo {
    public static void main(String[] args) {
        List<String> list = new ArrayList<String>();// 调用无参构造方法，默认初始大小为10
        list.add("一号");
        list.add("二号");
        list.add("三号");
        list.add("四号");
        list.add("五号");
        list.add(3, "0号");

        list.set(1, "element");
        System.out.println("使用迭代器对象来进行统一的遍历：");
        Iterator<String> it = list.iterator();
        while (it.hasNext()) {
            String name = it.next();
            System.out.println(name);
        }
        System.out.println("\n" + list.get(4) + "    " + list.size());

        System.out.println("\n使用增强for循环进行遍历：");
        for (String name : list) {
            System.out.println(name);
        }
    }
}
